﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace Chapter2ConsoleApp {
    class Program {
        static void Main(string[] args) {
            QueryContacts();
        }

        private static void QueryContacts() {
            using (var context = new SampleEntities()) {
                //var contacts = from c in context.Contacts
                //               where c.FirstName == "Robert"
                //               select c;

                var queryString = 
                    "SELECT VALUE c " +
                    "FROM SampleEntities.Contacts AS c " +
                    "WHERE c.FirstName='Robert'";
                ObjectQuery<Contact> contacts = context.CreateQuery<Contact>(queryString);
                
                foreach (var contact in contacts) {
                    Console.WriteLine("{0} {1}",
                        contact.FirstName.Trim(),
                        contact.LastName);
                }
            }
            Console.WriteLine("\nPress Enter...");
            Console.ReadLine();
        }
    }
}
